import React from 'react';
import { format } from '@/utils/datetime';
import CommonPage from '@/components/page/CommonPage';
import { renderNumber } from '@/utils/common';
const daoName = 'BasePara';

const columns: API.Column[] = [
  {
    title: '生效日期',
    width: 120,
    sorter: true,
    key: 'BGDT',
    caption: 'BGDT',
    render: (data) => format(data.BGDT, 'yyyy-MM-dd'),
    dispaly: true,
    canEdit: true,
    filter: true,
  },
  {
    title: '参数名称',
    width: 160,
    sorter: true,
    key: 'PAID',
    caption: 'ConfPara.Name',
    render: (data) => data.ConfPara.Name,
    dispaly: true,
    canEdit: true,
    filter: true,
    export: true,
  },
  {
    title: '值',
    width: 120,
    sorter: true,
    key: 'PAVL',
    dataIndex: 'PAVL',
    dispaly: true,
    canEdit: true,
    filter: true,
    export: true,
    align: 'right',
    render: (data) => renderNumber('.2f', data),
  },
  {
    title: '单位',
    width: 160,
    sorter: true,
    key: 'UNIT',
    caption: 'ConfPara.UNIT',
    render: (data) => data.ConfPara.UNIT,
    dispaly: true,
    canEdit: true,
    filter: false,
    export: true,
  },
];
const controls: API.Control[] = [
  {
    name: 'PAID',
    label: '参数名称',
    type: 'tree-select',
    grid: 12 / 24,
    rules: [{ required: true, message: '参数名称不能为空' }],
    dataType: 'number',
    fetch: {
      tableName: 'ConfPara',
      optionTpl: 'Name',
      valueTpl: 'ID',
      parentTpl: 'PAID',
      where: '"PATP"=2021',
      isDao: true,
    },
  },
  {
    name: 'BGDT',
    dataType: 'date',
    type: 'date',
    label: '生效日期',
    grid: 12 / 24,
    rules: [{ required: true, message: '生效日期不能为空' }],
  },
  {
    name: 'PAVL',
    rules: [{ required: true, message: '值不能为空' }],
    type: 'number',
    label: '值',
    grid: 12 / 24,
    dataType: 'number',
  },
];
const BasePara2021Form: React.FC = () => {
  return (
    <CommonPage
      daoName={daoName}
      columns={columns}
      controls={controls}
      title="考核参数2021"
      seeks={[
        {
          WhereItems: [
            {
              FieldName: 'ConfPara.PATP',
              Operator: 'in',
              FieldValues: '2021',
            },
          ],
          RelationSign: 'AND',
        },
      ]}
      initSorter={{
        FieldName: 'ConfPara.PATP',
        Direction: 'ASC',
      }}
    />
  );
};

export default BasePara2021Form;
